﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using RentalSystem.Data.EF.Core;
using Web.Context;
using RentalSystem.Data.EF;

namespace Web.Security
{
    public class UserRolesProvider:RoleProvider
    {
        IDataContext DataContext
        {
            get
            {
                return CurrentContext.Context.DataContext;
            }
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetRolesForUser(string username)
        {
            UserRoles role = DataContext.UsersDao.GetUserRole(username);

            if (role != null)
            {
                return new string[] { role.UserRoleName };
            }

            return new string[] {};
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            UserRoles role = DataContext.UsersDao.GetUserRole(username);

            if (role != null)
            {
                if (role.UserRoleName.Equals(roleName))
                    return true;
            }

            return false;
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }

    public static  class RoleType
    {
        public const string Customer = "Customer";
        public const string Worker = "Worker";
        public const string Administrator = "Administrator";
    }
}